package cn.com.dhcc.app.pub.core.consts;

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import cn.com.dhcc.app.core.AppEnv;
import cn.com.dhcc.app.core.AppEnv.ParaGetTool;
import cn.com.dhcc.app.core.exception.ServiceException;
import cn.com.dhcc.app.core.util.Const;
import cn.com.dhcc.app.core.util.NetUtil;
import cn.com.dhcc.turbo.service.exch.ApiUserAuthServiceImpl;

public class AppConst extends Const{
	
	/**
	 * 如果是水利则，则根据水利的权限来控制管理范围，例如注册，和建立交换关系
	 */
	public static final String platformType = AppEnv.ParaGetTool.getPara("platform.type");
	
	
	public static final String FTP = "ftp";
	
	
	
	//项目工作目录
	public static String APP_WORK_DIR=AppEnv.ParaGetTool.getPara("app.work.dir");
	//项目日志目录
	public static String LOG_PATH=AppEnv.ParaGetTool.getPara("log_path");
	//#常规数据报文存储根路径
	public static String CMDATA_STORED_DIR=APP_WORK_DIR+File.separator+"rawdata";
	
	
	//--------------------------------非结构化数据交换目录 start-------------------------------------------------------
		//#大文件数据头文件xml上传目录
		public static String FILEDATA_UPLOADXML_DIR="uploadxml";
		//#大文件数据数据上传目录
		public static String FILEDATA_UPLOADMETADATA_DIR="uploadmetadata";
		//#大文件数据解析成功响应目录
		public static String FILEDATA_SUCCESSXML_DIR="successxml";
		//#大文件数据解析失败响应目录
		public static String FILEDATA_FAILXML_DIR="failxml";
		//#中转文件目录
		public static String FILEDATA_CROSSMETADATA_DIR="crossmetadata";
		public static String FILEDATA_CROSSXML_DIR="crossxml";
		//#接收远程响应文件admin下
		public static String FILEDATA_REMOTERESP_DIR="remoteresp";
		//#接收本地响应文件admin下
		public static String FILEDATA_LOCALRESP_DIR="localresp";
		//#大文件数据接收头文件xml目录admin下;
		public static String FILEDATA_RECVXML_DIR="recvxml";
		//#大文件数据接收文件数据目录admin和其他用户都有
		public static String FILEDATA_RECVMETADATA_DIR="recvmetadata";
		
		//#FTP下载的临时目录
		public static String APP_GAP_FTP_INNER_LOCALFTPPUT=APP_WORK_DIR+File.separator+"ftp"+File.separator+"inner"+File.separator;
		//#FTP下载的临时目录
		public static String APP_GAP_FTP_OUT_LOCALFTPPUT=APP_WORK_DIR+File.separator+"ftp"+File.separator+"outer"+File.separator;;//app.gap.temp
		//cmdata生成文件的后缀
		public static String APP_GAP_TEMP_FILE=".json";
		
		
		
		//#大文件数据解析成功后头文件目录
		public static String FILEDATA_GLOBALTOSENDRESP_DIR=APP_WORK_DIR+File.separator+"filedata"+File.separator+"globaltosendresp";
		//#大文件数据解析成功后头文件目录
		public static String FILEDATA_GLOBALTORECVRESP_DIR=APP_WORK_DIR+File.separator+"filedata"+File.separator+"globaltorecvresp";
		//#大文件存储路径
		public static String FILEDATA_GLOBALUPLOADMETADATA_DIR=APP_WORK_DIR+File.separator+"filedata"+File.separator+"globaluploadmetadata";
		
		
		//#刻盘文件的工作目录
		//刻盘文件下载临时目录
		public static String APP_CD_TEMP=APP_WORK_DIR+File.separator+"down"+File.separator+"tmp";
		
		//刻盘文件下载的zip目录
		public static String APP_CD_ZIP=APP_WORK_DIR+File.separator+"down"+File.separator+"zip";
		//刻盘文件上传目录
		public static String APP_CD_UPLOAD=APP_WORK_DIR+File.separator+"upload"+File.separator+"normal";
		
		//刻盘文件上传待合包目录
		public static String APP_CD_UPLOAD_SPLIT=APP_CD_UPLOAD+File.separator+"split";
		
		//刻盘文件上传合包目录
		public static String APP_CD_UPLOAD_UNION=APP_CD_UPLOAD+File.separator+"union";
		
		
		//ftp网闸根目录
		public static String EMBFTP_ROOTDIR=APP_WORK_DIR+File.separator+"ftphome";
	   //---------------------------------非结构化数据交换目录 end---------------------------------------------------------
		
	
	public static DateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd");//根据日期创建文件夹
	public static DateFormat dtFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public static DateFormat dttFormat = new SimpleDateFormat("yyyyMMddHHmm");
	
	public static int FTP_TIMEOUT=5000;//FTP超时毫秒数
	
	public static final String installIp = ParaGetTool.getPara("app.install.ip").trim();
	
	public static final String mappingIp= ParaGetTool.getPara("app.mapping.ip").trim()!=null && !"".equals(ParaGetTool.getPara("app.mapping.ip").trim())
			? ParaGetTool.getPara("app.mapping.ip").trim() :installIp;
	
	
	public static final Boolean isCluster=ParaGetTool.getPara(Boolean.class, "app.cluster.enabled", false);
	/**
	 * 路由序列号
	 * @author Administrator
	 *
	 */
	public static enum RouteOrder{
		ROUTE_1("_1","路由1"),
		ROUTE_2("_2","路由2"),
		ROUTE_3("_3","路由3"),
		ROUTE_4("_4","路由4");
		
		private String order;
		private String desc;
		private RouteOrder(String order,String desc){
			this.order=order;
			this.desc=desc;
		}
		public String getOrder() {
			return order;
		}
		public void setOrder(String order) {
			this.order = order;
		}
		public String getDesc() {
			return desc;
		}
		public void setDesc(String desc) {
			this.desc = desc;
		}
		
	}
	
	//上传到网闸时的拆包大小
	public static Long FTP_FILESIZE=0l;
	static {
		String filesize=ParaGetTool.getPara("app.gap.ftp.fileSize");
		if (filesize==null || "".equals(filesize)) {
			FTP_FILESIZE=50*1024*1024l;
		}else{
			FTP_FILESIZE=Long.parseLong(filesize)*1024*1024l;
		}
		
	}
	
	//刻盘时的拆包大小
	public static Long CD_FILESIZE=0l;
	static {
		String filesize=ParaGetTool.getPara("app.cd.fileSize");
		if (filesize==null || "".equals(filesize)) {
			CD_FILESIZE=50*1024*1024l;
		}else{
			CD_FILESIZE=Long.parseLong(filesize)*1024*1024l;
		}
		
	}
	
	/**
	 * 平台管理员登陆时用的授权码
	 */
	private static final String authCodeForAdmin = EMBFTP.EMBFTP_ADMIN_USERID+"_"+mappingIp;
	//平台内部默认对称加密key
	public static final String desKeyForAdmin = "";
	//获取管理员登陆授权
	public static String getAdminAuthCode() throws ServiceException{
		return ApiUserAuthServiceImpl.createAuthCodeStatic(authCodeForAdmin);
	}
	/**
	 * 跨网类型
	 */
	public static enum CrossNetType {
		SAME_NETWORK("0","同网段"),
		INNER_OUT_NETWORK("1","内网到外网"),
		OUT_INNER_NETWORK("2","外网到内网");
		private String type;
		private String desc;
		private CrossNetType(String type, String desc) {
			this.type = type;
			this.desc = desc;
		}

		public String getType() {
			return type;
		}

		public String getDesc() {
			return desc;
		}

		public void setType(String type) {
			this.type = type;
		}

		public void setDesc(String desc) {
			this.desc = desc;
		}

		public String value() {
			return this.type;
		}

		@Override
		public String toString() {
			return type;
		}
		
		public static CrossNetType value(String value){
			if (value.equals(CrossNetType.SAME_NETWORK.value())) {
				return CrossNetType.SAME_NETWORK;
			}
			if (value.equals(CrossNetType.INNER_OUT_NETWORK.value())) {
				return CrossNetType.INNER_OUT_NETWORK;
			}
			if (value.equals(CrossNetType.OUT_INNER_NETWORK.value())) {
				return CrossNetType.OUT_INNER_NETWORK;
			}
			
			return null;
		}
	
	}
	
	/**
	 * 数据表
	 */
	public static enum FromTable{
		SEND_TABLE("0", "sendXXX表"),
		RECV_TABLE("1", "recvXXX表"), 
		TMP_TABLE("2", "CrossNetTmpXXX表");
		private String type;
		private String desc;

		private FromTable(String type, String desc) {
			this.type = type;
			this.desc = desc;
		}

		public String getType() {
			return type;
		}

		public String getDesc() {
			return desc;
		}

		public void setType(String type) {
			this.type = type;
		}

		public void setDesc(String desc) {
			this.desc = desc;
		}

		public String value() {
			return this.type;
		}

		@Override
		public String toString() {
			return type;
		}
	}
	
	/**
	 * 文件处理状态
	 */
	public static enum UploadProcessStatus {
		DATA_SENDING("0", "待发送"),
		DATA_PART_SENT("1", "部分发送"), 
		DATA_SENT("2", "已发送");
		private String type;
		private String desc;

		private UploadProcessStatus(String type, String desc) {
			this.type = type;
			this.desc = desc;
		}

		public String getType() {
			return type;
		}

		public String getDesc() {
			return desc;
		}

		public void setType(String type) {
			this.type = type;
		}

		public void setDesc(String desc) {
			this.desc = desc;
		}

		public String value() {
			return this.type;
		}

		@Override
		public String toString() {
			return type;
		}
	}
	/**
	 * 交换数据类型
	 */
	public static enum ExchDataType {
		CM_DATA("1", "结构化数据交换"), 
		FILE_DATA("2", "非结构化交换");
		private String type;
		private String desc;

		private ExchDataType(String type, String desc) {
			this.type = type;
			this.desc = desc;
		}

		public String getType() {
			return type;
		}

		public String getDesc() {
			return desc;
		}

		public void setType(String type) {
			this.type = type;
		}

		public void setDesc(String desc) {
			this.desc = desc;
		}

		public String value() {
			return this.type;
		}

		
		
		@Override
		public String toString() {
			return type;
		}
	}
	/**
	 * 上传文件解析状态
	 * 
	 * @日期 2014-10-17 上午10:14:45
	 * @作者  高强
	 */
	public static enum AnalyzeStatus{
		NOT_ANALYZE("0","待解析"),
		ANALYZE_SUCCESS("1","解析成功"),
		ANALYZE_FAIL("2","解析失败");
		private String type;
		private String desc;
		
		private AnalyzeStatus(String type, String desc) {
			this.type = type;
			this.desc = desc;
		}
		
		public String getType() {
			return type;
		}
		
		public String getDesc() {
			return desc;
		}
		
		public void setType(String type) {
			this.type = type;
		}
		
		public void setDesc(String desc) {
			this.desc = desc;
		}
		
		public String value() {
			return this.type;
		}
		
		@Override
		public String toString() {
			return type;
		}
	}
	public static enum ProcessStatus{
		NOT_CARVED_DISCS("0","待刻盘"),
		CARVED_DISCS("1","已刻盘");
		private String type;
		private String desc;
		
		private ProcessStatus(String type, String desc) {
			this.type = type;
			this.desc = desc;
		}
		
		public String getType() {
			return type;
		}
		
		public String getDesc() {
			return desc;
		}
		
		public void setType(String type) {
			this.type = type;
		}
		
		public void setDesc(String desc) {
			this.desc = desc;
		}
		
		public String value() {
			return this.type;
		}
		
		@Override
		public String toString() {
			return type;
		}
	}
	/**
	 * 消息类型
	 */
	public static enum MsgType {
		SINGLE_MSG("0", "一对一"),
		GROUP_MSG("1", "一点多发"),
		SUB_MSG("2", "--");
		private String type;
		private String desc;
		
		private MsgType(String type, String desc) {
			this.type = type;
			this.desc = desc;
		}
		
		public String getType() {
			return type;
		}
		
		public String getDesc() {
			return desc;
		}
		
		public void setType(String type) {
			this.type = type;
		}
		
		public void setDesc(String desc) {
			this.desc = desc;
		}
		
		public String value() {
			return this.type;
		}
		
		@Override
		public String toString() {
			return type;
		}
	}

	/**
	 * 发送状态
	 */
	public static enum PostheadStatus {
		OK("200", "OK"), //请求成功
		BAD_REQUEST("400", "Bad Request"), //参数异常
		INTERNAL_SERVER_ERROR("500", "Internal Server Error");//服务器异常
		private String status;
		private String desc;

		private PostheadStatus(String status, String desc) {
			this.status = status;
			this.desc = desc;
		}

		public String getStatus() {
			return status;
		}

		public String getDesc() {
			return desc;
		}

		public void setStatus(String status) {
			this.status = status;
		}

		public void setDesc(String desc) {
			this.desc = desc;
		}

		public String value() {
			return this.status;
		}

		@Override
		public String toString() {
			return status;
		}
	}
	
	/**
	 * 发送状态
	 */
	public static enum SendStatus {
		READY("0", "本地节点待发送"), 
		LOCAL_SENDING("11", "本地节点发送中"),//(本地消息队列)
		LOCAL_SENT("12", "本地已发送"), 
		
		WAIT_CARVED_DISCS("21", "待刻盘"),
		CARVED_DISCS("22", "已刻盘"),
		
		
		OUTER_ENTREPOT_READY("31",   "外网网闸节点已接收"),
		OUTER_ENTREPOT_SENDING("32",   "往网闸发送中"),
		OUTER_ENTREPOT_SUCCESS("33", "往网闸发送成功"),
		
		
		INNER_ENTREPOT_READY("41",   "内网网闸节点已接收"),
		INNER_ENTREPOT_SENDING("42", "内网网闸节点发送中"),
		INNER_ENTREPOT_SEND("43",   "内网网闸节点已发送"),
		
		ANALYZE_SUCESS("61", "刻盘文件解析成功"),
		ANALYZE_FAIL("62", "刻盘文件解析失败"),
		
		REMOTE_READY("51","目的节点已接收"),
        REMOTE_SENDING("52", "适配器接收中"),//发送中(远端业务系统)
        
		SENT("1", "已发送"), 
        FAIL("3", "发送失败");
		private String status;
		private String desc;

		private SendStatus(String status, String desc) {
			this.status = status;
			this.desc = desc;
		}

		public String getStatus() {
			return status;
		}

		public String getDesc() {
			return desc;
		}

		public void setStatus(String status) {
			this.status = status;
		}

		public void setDesc(String desc) {
			this.desc = desc;
		}

		public String value() {
			return this.status;
		}
		
		/**
		 * 这里将 LOCAL_SENDING 和  REMOTE_SENDING 都看成发送中
		 * @return
		 */
		public static SendStatus[] getSendStatus() {
			SendStatus[] arr = new SendStatus[4];
			arr[0] = SendStatus.READY;
			arr[1] = SendStatus.LOCAL_SENDING;
			arr[2] = SendStatus.SENT;
			arr[3] = SendStatus.FAIL;
			return arr;
		}

		@Override
		public String toString() {
			return status;
		}
	}
	
	
	/**
	 * 跨网发送状态
	 * 外网和内网的发送状态相对隔离
	 * 外网：待发送-发送至中转站-中转站待发送-发送至外网网闸-结束
	 * 内网：待发送-发送至目的节点-目的节点发送中-发送至外网网闸-结束
	 */
	public static enum CrossNetSendStatus {
		READY("0", "发送节点待发送"), 
		OUTER_ENTREPOT_SENDING("1", "往外网中转站发送中"),
		OUTER_ENTREPOT_FAIL("10", "往外网中转站发送失败"),
		OUTER_ENTREPOT_READY("2",   "往外网中转站待发送"),
		GAP_SENDING("3",   "往外网网闸发送中"),
		GAP_FAIL("30",   "往外网网闸发送失败"),
		GAP_SENT("4", "外网网闸发送成功"),
		INNER_ENTREPOT_READY("5", "内网中转站待发送"),
		INNER_ENTREPOT_SEDING("6", "内网中转站发送中"),
		INNER_ENTREPOT_FAIL("60", "内网中转站发送失败"),
		TARGET_NODE_READY("7", "目的节点待发送"),
		TARGET_NODE_SENDING("8", "目的节点待发送"),
		TARGET_NODE_FAIL("80", "目的节点待发送"),
		SENT("9", "目的节点发送成功");
		private String status;
		private String desc;
		
		private CrossNetSendStatus(String status, String desc) {
			this.status = status;
			this.desc = desc;
		}
		
		public String getStatus() {
			return status;
		}
		
		public String getDesc() {
			return desc;
		}
		
		public void setStatus(String status) {
			this.status = status;
		}
		
		public void setDesc(String desc) {
			this.desc = desc;
		}
		
		public String value() {
			return this.status;
		}
		
		/**
		 * 这里将 LOCAL_SENDING 和  REMOTE_SENDING 都看成发送中
		 * @return
		 */
		public static SendStatus[] getSendStatus() {
			SendStatus[] arr = new SendStatus[4];
			arr[0] = SendStatus.READY;
			arr[1] = SendStatus.LOCAL_SENDING;
			arr[2] = SendStatus.SENT;
			arr[3] = SendStatus.FAIL;
			return arr;
		}
		
		@Override
		public String toString() {
			return status;
		}
	}
	
	/**
	 * 消息发送通知状态
	 * 当SendStatus状态为SENT 或者 FAIL的时候通知发送系统
	 */
	public static enum NotifyStatus {
		READY("0", "待通知"), 
		NOTIFIED("1", "通知成功"), 
		NOTIFYING("2", "正在通知"), 
		FAIL("3", "通知失败");
		private String status;
		private String desc;

		private NotifyStatus(String status, String desc) {
			this.status = status;
			this.desc = desc;
		}

		public String getStatus() {
			return status;
		}

		public String getDesc() {
			return desc;
		}

		public void setStatus(String status) {
			this.status = status;
		}

		public void setDesc(String desc) {
			this.desc = desc;
		}

		public String value() {
			return this.status;
		}

		@Override
		public String toString() {
			return status;
		}
	}

    public static enum  NeedFeedback{
        NEED("0","需要"),NONEED("1","不需要");
        private  String type;
        private String desc;

        private NeedFeedback(String type, String desc) {
            this.type = type;
            this.desc = desc;
        }
        public String getType() {
            return type;
        }

        public String getDesc() {
            return desc;
        }

        public void setType(String type) {
            this.type = type;
        }

        public void setDesc(String desc) {
            this.desc = desc;
        }

        public String value() {
            return this.type;
        }

        @Override
        public String toString() {
            return type;
        }
    }
    /**
     * 系统 统计级别  统计级别： 1 节点 2 业务域 3 系统
     * @日期 2014-12-12 上午11:53:45
     * @作者  高强
     */
    public static enum StatLevel {
		NODE("1", "节点"),
		DOMAIN("2", "业务域"),
		ADAPTER("3","适配器");
		private String type;
		private String desc;

		private StatLevel(String type, String desc) {
			this.type = type;
			this.desc = desc;
		}

		public String getType() {
			return type;
		}

		public String getDesc() {
			return desc;
		}

		public void setType(String type) {
			this.type = type;
		}

		public void setDesc(String desc) {
			this.desc = desc;
		}

		public String value() {
			return this.type;
		}

		@Override
		public String toString() {
			return type;
		}
	}

	
    /**
     * 1发送， 2接收
     * 统计类型
     * @日期 2014-12-12 上午11:53:45
     * @作者  高强
     */
    public static enum StaExchType {
		SEND("1", "发送"),
		RECV("2", "接收");
		private String type;
		private String desc;

		private StaExchType(String type, String desc) {
			this.type = type;
			this.desc = desc;
		}

		public String getType() {
			return type;
		}

		public String getDesc() {
			return desc;
		}

		public void setType(String type) {
			this.type = type;
		}

		public void setDesc(String desc) {
			this.desc = desc;
		}

		public String value() {
			return this.type;
		}

		@Override
		public String toString() {
			return type;
		}
	}
    
	/**
	 * 数据传输通道
	 */
	public static enum Pipeline {
		TLQ("TLQ", "TLQ消息中间件传输通道"); 
		//HTTP("HTTP", "HTTP传输通道");
		//AMQ("AMQ", "AMQ传输通道"), 
		//Netty("Netty", "Netty传输通道");
		private String type;
		private String desc;

		private Pipeline(String type, String desc) {
			this.type = type;
			this.desc = desc;
		}

		public String getType() {
			return type;
		}

		public String getDesc() {
			return desc;
		}

		public void setType(String type) {
			this.type = type;
		}

		public void setDesc(String desc) {
			this.desc = desc;
		}

		public String value() {
			return this.type;
		}

		@Override
		public String toString() {
			return type;
		}
	}

	/**
	 * 数据发送优先级 1、2、3、4、5 优先级数字越小发送越快，默认值：3，选填项
	 */
	public static enum Priority {
		FASTER("1", "优先级最高"), 
		FAST("2", "优先级次高"), 
		NORMAL("3", "默认优先级"), 
		SLOW("4", "优先级低"), 
		SLOWER("5", "优先级次低");
		private String type;
		private String desc;

		private Priority(String type, String desc) {
			this.type = type;
			this.desc = desc;
		}

		public String getType() {
			return type;
		}

		public String getDesc() {
			return desc;
		}

		public void setType(String type) {
			this.type = type;
		}

		public void setDesc(String desc) {
			this.desc = desc;
		}

		public String value() {
			return this.type;
		}

		@Override
		public String toString() {
			return type;
		}
	}
	

	
	/**
	 * 内嵌ftp根目录
	 * FTP基本信息参数
	 * @author qiao
	 * @2014-6-13 @下午4:15:41
	 */
	public static final class EMBFTP {
		public static final Integer EMBFTP_PORT_DEFAULT = 21;
		public static final String EMBFTP_ADMIN_USERID = "admin";
		public static final String EMBFTP_ADMIN_PWD = "admin";
		public static final String EMBFTP_ROOTDIR = AppConst.EMBFTP_ROOTDIR;
		
		public static final String  EMBFTP_PASS_PORT=ParaGetTool
				.getPara(String.class, "embftp.pass-port", null);
		public static final Integer EMBFTP_PORT = ParaGetTool
				.getPara(Integer.class, "embftp.port", EMBFTP_PORT_DEFAULT);
		public static final Integer EMBFTP_MAX_LOGINS = ParaGetTool.getPara(Integer.class, "embftp.max-logins", 500);
		public static final Integer EMBFTP_MAX_THREADS = ParaGetTool.getPara(Integer.class, "embftp.max-threads", 500);
	}
	
	public static List<String> localIpStyle = new ArrayList<String>() {
		private static final long serialVersionUID = 1L;
		{
			add("localhost");
			add("127.0.0.1");
			add("0.0.0.1");
			add(NetUtil.getLocalHostIp());
			add(NetUtil.getLocalHostName());
		}};

		
		 public static enum OBJECT_TYPE {
			 	GLOBAL("0","全局"),
			 	PARTIAL("1","局部");
				private String code;
				private String name;
				OBJECT_TYPE(String code,String name){
					this.code = code;
					this.name = name;
				}
				public String getName() {
					return name;
				}
				public String getCode() {
					return code;
				}
		    }
		
}
